Skip to content

[Fix-18274] Fix client heartbeat not updated after database out of service for longer than session timeout time#18275

Open
qiong-zhou wants to merge 2 commits into
apache:devfrom
qiong-zhou:Fix-18274
Open

[Fix-18274] Fix client heartbeat not updated after database out of service for longer than session timeout time#18275
qiong-zhou wants to merge 2 commits into
apache:devfrom
qiong-zhou:Fix-18274

Conversation

@qiong-zhou
Copy link
Copy Markdown
Contributor

After database out of service for longer than session timeout time, client heartbeat will never be updated

Was this PR generated or assisted by AI?

NO

Purpose of the pull request

Fix client heartbeat not updated after database out of service for longer than session timeout time

Brief change log

  • Modified JdbcRegistryClientHeartbeatMapper.java
  • Modified JdbcRegistryClientRepository.java
  • Modified JdbcRegistryServer.java

Verify this pull request

This pull request is code cleanup without any test coverage.

Pull Request Notice

Pull Request Notice

If your pull request contains incompatible change, you should also add it to docs/docs/en/guide/upgrade/incompatible.md

After database out of service for longer than session timeout time, client heartbeat will never be updated
@SbloodyS SbloodyS added the bug Something isn't working label May 20, 2026
@SbloodyS SbloodyS added this to the 3.4.2 milestone May 20, 2026
JdbcRegistryClientHeartbeatDTO clone = jdbcRegistryClientHeartbeatDTO.clone();
clone.setLastHeartbeatTime(now);
jdbcRegistryClientRepository.updateById(jdbcRegistryClientHeartbeatDTO);
jdbcRegistryClientRepository.upsert(jdbcRegistryClientHeartbeatDTO);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better don't use upsert here, if the client heartbeat has been removed, then we should shutdown, since the server might have been failovered by other server.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the client is not down. The connection to the database is unreachable within more than a session timeout time. When the database is available, the client will send the heartbeat with the same client ID.
You mean in this case, the client should generate an new client ID and insert a new client record?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the session times out and the heartbeat is removed, the server/client should stop rather than reinsert a heartbeat, because at this point other servers may have already detected that the heartbeat is down and initiated fault-tolerance procedures.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more recommended approach would be to throw an exception when

jdbcRegistryClientRepository.updateById(jdbcRegistryClientHeartbeatDTO);

fails, and make refreshClientsHeartbeat return directly when jdbcRegistryServerState == JdbcRegistryServerState.DISCONNECTED.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this client should be restarted manually to register it again?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The client shouldn't restarted, it should shutdown

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I'm confused. How to register this client again?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a session times out, indicating that the client has disconnected, a disconnection event must be triggered, and the service will automatically terminate without requiring re-registration.

After database out of service for longer than session timeout time, client heartbeat will never be updated
@qiong-zhou qiong-zhou requested review from SbloodyS and ruanwenjun May 21, 2026 03:31
@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants